Skip to content

Conversation

@lovelydinosaur
Copy link
Contributor

We have a leftover bit of API on SyncByteStream/AsyncByteStream that is a hangover from when we were designing the Transport API.

They both have a convenience method for reading the stream, which was added to make testing at the low-level of the Transport API easier. However the methods are a bit kludgy because they don't actually fit the read(max_bytes) that Python file interfaces use.

I think we can just hard-drop these. They're undocumented, and you don't ever need them. The convenience methods are on the Response class.

@lovelydinosaur lovelydinosaur added the refactor Issues and PRs related to code refactoring label Oct 13, 2022
assert isinstance(stream, httpx.AsyncByteStream)

sync_content = stream.read()
async_content = await stream.aread()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're matching the style of the other test cases now.
These .read()/.aread() operations were only added to this test case so that we'd have coverage of those code lines.

self._is_stream_consumed = True
if hasattr(self._stream, "read") and not isinstance(
self._stream, SyncByteStream
):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The and not isinstance(self._stream, SyncByteStream) is what prompted me to clean these up.

It's such an oddly confusing branch - I couldn't figure out why it existed.

"Treat file-like objects as file-like objects, except for this one specific case".

No thanks.

Comment on lines -116 to -120
status_code, headers, stream, extensions = transport.handle_request(...)
try:
...
finally:
stream.close()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an example from the old-style Transport API.

We had .read() so that users could eg. stream.read() here.

The Transport API now just returns fully fledged responses, so this is redundant.

@lovelydinosaur
Copy link
Contributor Author

Thanks for the review @michaeloliverx.
Anyone want to merge this?...

@lovelydinosaur
Copy link
Contributor Author

...How should we handle that generally?
Default to "pull request owner" can merge once approved?

@michaeloliverx
Copy link
Contributor

...How should we handle that generally? Default to "pull request owner" can merge once approved?

I think this is okay, maybe if you are personally reviewing something you can go ahead and merge it yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Issues and PRs related to code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants